home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / ibmcom.zip / DEMO.C < prev    next >
Text File  |  1989-04-29  |  3KB  |  100 lines

  1. /* 
  2.  
  3.     The IBMCOM library implements a simple set of interrupt
  4.    routines for ports 1 thru 4 of the IBM PC/XT/AT family and
  5.    clones.    The interrupt routines use circular buffers. These
  6.    routines have been tested up 112 kbaud.  Buffer sizes and
  7.    other features can be changed    by changing defines in ibmcom's
  8.    source code.
  9.  
  10.     The input side of the routines are interrupt driven using the
  11.     conventional approach to implementing interrupts with TurboC.
  12.    The output side of the routines use a simple polled technique
  13.    or optionally are interrupt driven.
  14.  
  15.    If you have any comments lets us know via our compuserve number
  16.    (75036,1602). Any bugs?  Let us know.
  17.  
  18.                                     Thanks 
  19.                                     Al Morgan
  20.  
  21.         PS. This code is subject to the normal disclaimer. We specifically
  22.     disclaim all warranties, expressed or implied, including but not
  23.     limited to implied warranties of merchantability and fitness for a
  24.     particular purpose with respect to defects in the documentation and
  25.     with     respect to any particular application, use, or     purpose.  In
  26.     no event shall Intrinsic be liable for any loss of profit or any
  27.     other commercial damage, including but not limited to special,
  28.     incidental consequential or other damages.           
  29.                                                                                 */
  30.  
  31.    #include "ibmcom.h"
  32.     #include "circ_buf.h"            /* contains circular buffer structure definitions */
  33.  
  34.     #define        FALSE                        0
  35.     #define        TRUE                        1
  36.  
  37. main()
  38. {
  39.     int pe,i,j,nc,port;
  40.     char tbuffer[100];
  41. /*
  42.  
  43.     This main routine is mainly for testing the communications routines.
  44.     Its also shows how the routine can be used, and in what sequence.
  45.  
  46.                                                                                             */
  47.     printf("Testing %s\n",__FILE__);
  48.     printf("Version Date: %s, Time: %s\n",__DATE__,__TIME__);
  49.     port = 1;
  50.  
  51.  
  52.     /* First initialize the ports baud rate, parity, etc */
  53.  
  54.     if( init_port(port,19,'n',8,1) != TRUE)
  55.     {
  56.         puts("Error on initializing the baud rate,etc\n");
  57.         exit(0);
  58.     }
  59.  
  60.     /* Next initialize the interrupt drivers for the port */
  61.  
  62.     if(!init_handl(port))
  63.    {
  64.       puts("Error on intializing the interrupt handlers\n");
  65.       exit(0);
  66.    }
  67.  
  68.     /* Initialize the interrupt output buffers for the port */
  69.    /* Only needed if you want to use interrupt driven output */
  70.  
  71.       init_buffer_out(port);
  72.  
  73.    puts("Press the ESC key to exit this demo...");
  74.    putsi_com(port,"Hello\n\r",7);      /* interrupt driven output */
  75.  
  76.  
  77. do
  78.     {
  79.         if( (pe=check_port_hw(port)) < 0 ) /* If < 0 then a port error */
  80.         {
  81.             printf("Port Error 0x%02x%c\n",-pe,7);
  82.             report_serial_status(-pe);    /* print out the error code in english */
  83.            report_circ_status(port);     /* for debugging */
  84.         }
  85.         if(pe > 0 )    /* If no port errors, see any chars in ports buffer */
  86.         {
  87.             while((nc = gets_com (tbuffer,sizeof(tbuffer),port)) != 0)
  88.             {
  89.             printf("\nPrint out of buffer nc = %d\n",nc);
  90.             putsi_com(port,"Hello\n\r",7);
  91.                 for(i=0;i<nc;i++)
  92.                     putch(tbuffer[i]);      /* display the characters on the console */
  93.             }
  94.         }
  95.     }
  96.     while(ci() != 27);
  97.     reset_port(port);        /* before we exit, turn off interrupts */
  98.    printf("Exiting program...\n");
  99. }
  100.